home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Offline Browsing / HTTrack.exe / data1.cab / Sources / src / htslib.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-28  |  13.1 KB  |  434 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche and other contributors
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: Subroutines .h                                         */
  34. /* Author: Xavier Roche                                         */
  35. /* ------------------------------------------------------------ */
  36.  
  37. // Fichier librairie .h
  38.  
  39. #ifndef HTS_DEFH
  40. #define HTS_DEFH 
  41.  
  42. /* dΘfinitions globales */
  43. #include "htsglobal.h"
  44.  
  45. /* basic net definitions */
  46. #include "htsbasenet.h"
  47.  
  48. /* cookies et auth */
  49. #include "htsbauth.h"
  50.  
  51. // Attention, dΘfinition existante Θgalement dans le shell
  52. // (α modifier avec celle-ci)
  53. #define POSTTOK "?>post"
  54.  
  55. #include <stdio.h>
  56.  
  57. /*
  58. #if HTS_WIN
  59.  #include <winsock.h>
  60.  typedef SOCKET T_SOC;
  61.  typedef struct hostent FAR t_hostent;
  62. #else
  63.  typedef int T_SOC;
  64.  typedef struct hostent t_hostent;
  65. #endif
  66. */
  67.  
  68. /*
  69. #include <ctype.h>
  70. #if HTS_WIN
  71.  #include <winsock.h>
  72.  typedef SOCKET T_SOC;
  73.  // pour read
  74.  #include <io.h>
  75.  // pour FindFirstFile
  76.  #include <winbase.h>
  77. #else
  78.  typedef int T_SOC;
  79.  #define INVALID_SOCKET -1
  80.  #include <netdb.h>
  81.  #include <sys/types.h>
  82.  #include <sys/socket.h>
  83.  #include <netinet/in.h>
  84.  #include <sys/time.h>
  85.  #include <sys/ioctl.h>
  86.  // gethostname & co0
  87.  #include <unistd.h>
  88.  // inet_addr
  89.  #include <arpa/inet.h>
  90.  // pas la peine normalement..
  91. #if HTS_PLATFORM!=3
  92.  #include <sys/filio.h>
  93. #else
  94. #ifndef HTS_DO_NOT_REDEFINE_in_addr_t
  95.  typedef unsigned long in_addr_t;
  96. #endif
  97. #endif
  98.  
  99. #ifndef min
  100.  #define min(a,b) ((a)>(b)?(b):(a))
  101.  #define max(a,b) ((a)>(b)?(a):(b))
  102. #endif
  103. #define Sleep(a) { if (((a)*1000)%1000000) usleep(((a)*1000)%1000000); if (((a)*1000)/1000000) sleep(((a)*1000)/1000000); }
  104. #endif
  105. */
  106.  
  107. /*
  108. #include <stdio.h>
  109. #include <stdlib.h>
  110. #include <string.h>
  111. #include <time.h>
  112. #include <fcntl.h>
  113. // pour utimbuf
  114. #if HTS_PLATFORM!=3
  115. #include <utime.h>
  116. #else
  117. #include <utime.h>
  118. #endif
  119. */
  120.  
  121.  /*
  122. // teste ΘgalitΘ de 2 chars, case insensitive
  123. #define hichar(a) ((((a)>='a') && ((a)<='z')) ? ((a)-('a'-'A')) : (a))
  124. #define streql(a,b) (hichar(a)==hichar(b))
  125.  
  126. // caractΦre maj
  127. #define isUpperLetter(a) ( ((a) >= 'A') && ((a) <= 'Z') )
  128. */
  129. /*
  130. #if HTS_PLATFORM!=3
  131. #ifdef __cplusplus
  132. extern "C" {
  133. #endif
  134. #if HTS_PLATFORM!=2
  135. #if HTS_PLATFORM!=1
  136.  int   open      (const char *, int, ...);
  137. #endif
  138.  //int   read      (int,const char*,int);
  139.  //int   write     (int,char*,int);
  140. #endif
  141. #if HTS_PLATFORM!=1
  142.  int   close     (int);
  143.  void* calloc    (size_t,size_t);
  144.  void* malloc    (size_t);
  145.  void* realloc   (void*,size_t);
  146.  void  free      (void*);
  147. #endif
  148. #if HTS_WIN==0
  149.  void  bzero     (char*,unsigned int);
  150.  void  bcopy     (const char*,char*,unsigned int);
  151.  //int   strcasecmp(const char*,const char*);
  152. #endif
  153.  //int   strlen    (const char *);
  154. #if HTS_WIN
  155.  //int   mkdir     (const char*);
  156. #else
  157.  int   mkdir     (const char*,mode_t);
  158.  int   isdigit   (char);
  159.  int   isalpha   (char);
  160.  int   isalnum   (char);
  161. #endif
  162. #ifdef __cplusplus
  163. }
  164. #endif
  165. #endif
  166. */
  167.  
  168. /*
  169. // conversion Θventuelle / vers antislash
  170. #if HTS_WIN
  171. char* antislash(char* s);
  172. #else
  173. #define antislash(A) (A)
  174. #endif
  175. */
  176.  
  177. /*
  178. #if HTS_WIN
  179. #define  bzero(a,b) memset(a,0,b)
  180. #define  bcopy(a,b,c) memcpy(b,a,c)
  181. #endif
  182.  
  183. // tracer malloc()
  184. #if HTS_TRACE_MALLOC
  185. #define malloct(A)    hts_malloc(A,0)
  186. #define calloct(A,B)  hts_malloc(A,B)
  187. #define freet(A)      hts_free(A)
  188. #define realloct(A,B) hts_realloc(A,B)
  189. void  hts_freeall();
  190. void* hts_malloc    (size_t,size_t);
  191. void  hts_free      (void*);
  192. void* hts_realloc   (void*,size_t);
  193. #else
  194. #define malloct(A)    malloc(A)
  195. #define calloct(A,B)  calloc(A,B)
  196. #define freet(A)      free(A)
  197. #define realloct(A,B) realloc(A,B)
  198. #endif
  199. */
  200.  
  201. #include "htsopt.h"
  202.  
  203. // structure pour paramΦtres supplΘmentaires lors de la requΩte
  204. typedef struct {
  205.   short int user_agent_send;  // user agent (ex: httrack/1.0 [sun])
  206.   short int http11;           // l'en tΩte peut (doit) Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  207.   char user_agent[64];
  208.   char lang_iso[64];
  209.   t_proxy proxy;              // proxy
  210. } htsrequest;
  211.  
  212.  
  213. // structure pour retour d'une connexion/prise d'en tΩte
  214. typedef struct {
  215.   int statuscode;        // status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
  216.   short int notmodified; // page ou fichier NON modifiΘ (transfΘrΘ)
  217.   short int is_write;    // sortie sur disque (out) ou en mΘmoire (adr)
  218.   short int is_chunk;    // mode chunk
  219.   char* adr;             // adresse du bloc de mΘmoire, NULL=vide
  220.   FILE* out;             // Θcriture directe sur disque (si is_write=1)
  221.   LLint size;            // taille fichier
  222.   char msg[80];          // message Θventuel si Θchec ("\0"=non prΘcisΘ)
  223.   char contenttype[64];  // content-type ("text/html" par exemple)
  224.   char* location;        // on copie dedans Θventuellement la vΘritable 'location'
  225.   LLint totalsize;       // taille totale α tΘlΘcharger (-1=inconnue)
  226.   short int is_file;     // ce n'est pas une socket mais un descripteur de fichier si 1
  227.   T_SOC soc;             // ID socket
  228.   FILE* fp;              // fichier pour file://
  229.   char lastmodified[64]; // Last-Modified
  230.   char etag[64];         // Etag
  231.   char cdispo[256];      // Content-Disposition coupΘ
  232.   /* */
  233.   htsrequest req;  // paramΦtres pour la requΩte
  234.   /*char digest[32+2];  // digest md5 gΘnΘrΘ par le moteur ("" si non gΘnΘrΘ)*/
  235. } htsblk;
  236.  
  237.  
  238. /* ANCIENNE STURCTURE pour cache 1.0 */
  239. typedef struct {
  240.   int statuscode;  // ANCIENNE STURCTURE - status-code, -1=erreur, 200=OK,201=..etc (cf RFC1945)
  241.   int notmodified; // ANCIENNE STURCTURE - page ou fichier NON modifiΘ (transfΘrΘ)
  242.   int is_write;    // ANCIENNE STURCTURE - sortie sur disque (out) ou en mΘmoire (adr)
  243.   char* adr;       // ANCIENNE STURCTURE - adresse du bloc de mΘmoire, NULL=vide
  244.   FILE* out;       // ANCIENNE STURCTURE - Θcriture directe sur disque (si is_write=1)
  245.   int size;        // ANCIENNE STURCTURE - taille fichier
  246.   char msg[80];    // ANCIENNE STURCTURE - message Θventuel si Θchec ("\0"=non prΘcisΘ)
  247.   char contenttype[64];  // ANCIENNE STURCTURE - content-type ("text/html" par exemple)
  248.   char* location;  // ANCIENNE STURCTURE - on copie dedans Θventuellement la vΘritable 'location'
  249.   int totalsize;   // ANCIENNE STURCTURE - taille totale α tΘlΘcharger (-1=inconnue)
  250.   int is_file;     // ANCIENNE STURCTURE - ce n'est pas une socket mais un descripteur de fichier si 1
  251.   T_SOC soc;       // ANCIENNE STURCTURE - ID socket
  252.   FILE* fp;        // ANCIENNE STURCTURE - fichier pour file://
  253.   t_proxy proxy;   // ANCIENNE STURCTURE - proxy
  254.   int user_agent_send;  // ANCIENNE STURCTURE - user agent (ex: httrack/1.0 [sun])
  255.   char user_agent[64];
  256.   int http11;           // ANCIENNE STURCTURE - l'en tΩte doit Ωtre signΘ HTTP/1.1 et non HTTP/1.0
  257. } OLD_htsblk;
  258. /* fin ANCIENNE STURCTURE pour cache 1.0 */
  259.  
  260. // cache pour le dns, pour Θviterd de faire des gethostbyname sans arrΩt
  261. typedef struct t_dnscache {
  262.   char iadr[1024];
  263.   char host_addr[16];    // 4 octets normalement ()
  264.   int host_length;       // 4 normalement - ==0  alors en cours de rΘsolution
  265.                          //                 ==-1 alors erreur (host n'Θxiste pas)
  266.   struct t_dnscache* n;
  267. } t_dnscache;
  268.  
  269.  
  270. typedef struct {
  271.   LLint HTS_TOTAL_RECV;      // flux entrant reτu
  272.   LLint stat_bytes;          // octets Θcrits sur disque
  273.   int HTS_TOTAL_RECV_STATE;  // status: 0 tout va bien 1: ralentir un peu 2: ralentir 3: beaucoup
  274.   double stat_timestart;     // dΘpart
  275.   double imstat_timestart;   // dΘpart pour calcul instantannΘ
  276.   LLint  istat_bytes;        // calcul pour instantannΘ
  277.   int stat_files;            // nombre de fichiers Θcrits
  278.   int stat_updated_files;    // nombre de fichiers mis α jour
  279.   //
  280.   LLint rate;
  281. } hts_stat_struct;
  282.  
  283.  
  284.  
  285. /*
  286. #ifdef __cplusplus
  287. extern "C" {
  288. #endif
  289. */
  290.  
  291. // fonctions unix/winsock
  292. int hts_read(htsblk* r,char* buff,int size);
  293. void HTS_TOTAL_RECV_CHECK(int var);
  294.  
  295. // fonctions principales
  296. int http_fopen(char* adr,char* fil,htsblk* retour);
  297. int http_xfopen(int mode,int treat,int waitconnect,char* xsend,char* adr,char* fil,htsblk* retour);
  298. int http_sendhead(t_cookie* cookie,int mode,char* xsend,char* adr,char* fil,char* referer_adr,char* referer_fil,htsblk* retour);
  299. htsblk httpget(char* url);
  300. //int newhttp(char* iadr,char* err=NULL);
  301. int newhttp(char* iadr,htsblk* retour,int port,int waitconnect);
  302. HTS_INLINE void deletehttp(htsblk* r);
  303. HTS_INLINE void deletesoc(T_SOC soc);
  304. htsblk http_location(char* adr,char* fil,char* loc);
  305. htsblk http_test(char* adr,char* fil,char* loc);
  306. void http_fread(T_SOC soc,htsblk* retour);
  307. LLint http_fread1(htsblk* r);
  308. void treathead(t_cookie* cookie,char* adr,char* fil,htsblk* retour,char* rcvd);
  309. void treatfirstline(htsblk* retour,char* rcvd);
  310. void infostatuscode(char* msg,int statuscode);
  311.  
  312. // sous-fonctions
  313. htsblk xhttpget(char* adr,char* fil);
  314. htsblk http_gethead(char* adr,char* fil);
  315. LLint http_xfread1(htsblk* r,int bufl);
  316. HTS_INLINE t_hostent* hts_gethostbyname(char* iadr);
  317. t_hostent* _hts_ghbn(t_dnscache* cache,char* iadr,t_hostent* retour);
  318. int ftp_available(void);
  319. #if HTS_DNSCACHE
  320. int hts_dnstest(char* _iadr);
  321. t_dnscache* _hts_cache(void);
  322. int _hts_lockdns(int i);
  323. #endif
  324.  
  325. // outils divers
  326. HTS_INLINE double time_local(void);
  327. HTS_INLINE double mtime_local(void);
  328. void sec2str(char *s,double t);
  329. void qsec2str(char *st,double t);
  330. void time_gmt_rfc822(char* s);
  331. void time_local_rfc822(char* s);
  332. struct tm* convert_time_rfc822(char* s);
  333. int set_filetime(char* file,struct tm* tm_time);
  334. int set_filetime_rfc822(char* file,char* date);
  335. HTS_INLINE void time_rfc822(char* s,struct tm * A);
  336. HTS_INLINE void time_rfc822_local(char* s,struct tm * A);
  337. char* int2bytes(LLint n);
  338. char* int2bytessec(long int n);
  339. char** int2bytes2(LLint n);
  340. HTS_INLINE int sendc(T_SOC soc,char* s);
  341. void finput(int fd,char* s,int max);
  342. int binput(char* buff,char* s,int max);
  343. void linput(FILE* fp,char* s,int max);
  344. void linput_trim(FILE* fp,char* s,int max);
  345. void linput_cpp(FILE* fp,char* s,int max);
  346. void rawlinput(FILE* fp,char* s,int max);
  347. int strfield(const char* f,const char* s);
  348. #define strfield2(f,s) ( (strlen(f)!=strlen(s)) ? 0 : (strfield(f,s)) )
  349. char* strstrcase(char *s,char *o);
  350. int ident_url(char* url,char* adr,char* fil);
  351. void fil_simplifie(char* f);
  352. int ishtml(char* urlfil);
  353. int ishtml_ext(char* a);
  354. int ishttperror(int err);
  355. void guess_httptype(char *s,char *fil);
  356. void get_httptype(char *s,char *fil,int flag);
  357. void give_mimext(char *s,char *st);
  358. int is_knowntype(char *fil);
  359. char* get_ext(char *fil);
  360. int may_unknown(char* st);
  361. char* jump_identification(char*);
  362. HTS_INLINE char* jump_protocol(char* source);
  363. void code64(char* a,char* b);
  364. void unescape_amp(char* s);
  365. void escape_spc_url(char* s);
  366. void escape_in_url(char* s);
  367. void escape_check_url(char* s);
  368. void x_escape_http(char* s,int mode);
  369. HTS_INLINE int ehexh(char c);
  370. char* unescape_http(char* s);
  371. char* antislash_unescaped(char* s);
  372. int ehex(char* s);
  373. char* concat(const char* a,const char* b);
  374. #define copychar(a) concat((a),NULL)
  375. #if HTS_DOSNAME
  376. char* fconcat(char* a,char* b);
  377. char* fconv(char* a);
  378. #else
  379. #define fconv(a) (a)
  380. #define fconcat(a,b) concat(a,b)
  381. #endif
  382. char* fslash(char* a);
  383. char* __fslash(char* a);
  384.  
  385. char* convtolower(char* a);
  386. char* concat(const char* a,const char* b);
  387. void hts_lowcase(char* s);
  388. void hts_replace(char *s,char from,char to);
  389.  
  390. /* Spaces: CR,LF,TAB,FF */
  391. #define  is_space(c)     ( ((c)==' ') || ((c)=='\"') || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12) || ((c)=='\'') )
  392. #define  is_realspace(c) ( ((c)==' ')                || ((c)==10) || ((c)==13) || ((c)==9) || ((c)==12)                )
  393. //HTS_INLINE int is_space(char);
  394. //HTS_INLINE int is_realspace(char);
  395.  
  396. void cut_path(char* fullpath,char* path,char* pname);
  397. int fexist(char* s);
  398. /*LLint fsize(char* s);    */
  399. int fpsize(FILE* fp);
  400. int fsize(char* s);    
  401.  
  402. // Threads
  403. #if USE_PTHREAD
  404. typedef void* ( *beginthread_type )( void * );
  405. unsigned long _beginthread( beginthread_type start_address, unsigned stack_size, void *arglist );
  406. #endif
  407.  
  408. /*
  409. #ifdef __cplusplus
  410. }
  411. #endif
  412. */
  413.  
  414.  
  415.  
  416. /* variables globales */
  417. //extern LLint HTS_TOTAL_RECV;  // flux entrant reτu
  418. //extern int HTS_TOTAL_RECV_STATE;  // status: 0 tout va bien 1: ralentir un peu 2: ralentir 3: beaucoup
  419. extern hts_stat_struct HTS_STAT;
  420. extern int _DEBUG_HEAD;
  421. extern FILE* ioinfo;
  422.  
  423. /* constantes */
  424. extern const char hts_mime_keep[][32];
  425. extern const char hts_mime[][2][32];
  426. extern const char hts_detect[][32];
  427. extern const char hts_detectURL[][32];
  428. extern const char hts_detectandleave[][32];
  429. extern const char hts_detect_js[][32];
  430.  
  431. #endif
  432.  
  433.  
  434.